package model;

import java.io.Serializable;
import java.util.List;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Version;


/**
 * The persistent class for the train database table.
 * 
 */
@Entity
@NamedQuery(name= "Train.findTrainByNumber", query="select t from Train t where t.trainNumber = :trainNumber")
public class Train implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final String FIND_BY_NUMBER = "Train.findTrainByNumber";
	
	@Id 
	private int trainID = Math.abs(UUID.randomUUID().hashCode());
	
	private int version;

	private int places;

	private int trainNumber;

	//bi-directional many-to-one association to Schedule
	@OneToMany(mappedBy="train", cascade = CascadeType.ALL, orphanRemoval = true)
	private List<Schedule> schedules;

	public Train() {
	}
	
	@Version
	public int getVersion() {
		return version;
	}

	@Version
	public void setVersion(int version) {
		this.version = version;
	}

	public int getTrainID() {
		return this.trainID;
	}

	public void setTrainID(int trainID) {
		this.trainID = trainID;
	}

	public int getPlaces() {
		return this.places;
	}

	public void setPlaces(int places) {
		this.places = places;
	}

	public int getTrainNumber() {
		return this.trainNumber;
	}

	public void setTrainNumber(int trainNumber) {
		this.trainNumber = trainNumber;
	}

	public List<Schedule> getSchedules() {
		return this.schedules;
	}

	public void setSchedules(List<Schedule> schedules) {
		this.schedules = schedules;
	}

}